Page Producer
As we have seen in the previous topics, there are two types of pages: Static pages
that can be designed using HTML code or HTML producer such as FrontPage, and Dynamic
pages that can be produced by our CGI/ISAPI application. Static pages lacks the ability
of changing it's data according to user request, in another words, static pages cann't
get a result from it's web server, but it is very easy to design. Dynamic pages can
be a result of a process happens in the server such as searching in a database, but
dynamic pages lacks the design. We must write all the HTML code by hand to responde
to our clients. The question now is: how can we design our dynamic pages using HTML
producers and how can we make static pages acts like dynamic pages. We need to combine
the benefits of static pages and dynamic pages.
The solution of above problem is to use PageProducer component. We can design any
HTML page using HTML producer and we can put some variables (tags) in this page to
be replaced later by appropriate data by our web application according to client
request and server process.
Example of using PageProducer:
In this example we want to display the server date and time (dynamic data) but we
want to design the interface page by one of our favorite HTML pages producers (static
page).
- Design a page in your HTML producer, for example FrontPage and include this tag
in the HTML code:
<#time>. You can put this tag in any place you want your web application to display
the time in. If we see the HTML result it can be some thing like this:
Server time
Time in server example
The time in server is: <#time>
Copyright (c) 2001
- Save that file as time.htm
- Start new CGI application and name it "Time".
- Add new WebActionItem.
- Drop PageProducer from Internet page.
- At PageProducer's HTMLFile property select time.htm
- An PageProducer's OnTag event write this code:
if TagString = 'time' then
ReplaceText:= DateTimeToStr(Now);
- At WebActionItem1's OnAction event write:
Response.Content:= PageProducer1.Content
Compile the application and see the result.
You can include more than tag in one page. Example of multiple tags:
if TagString = 'time' then
ReplaceText:= TimeToStr(Time)
else
if TagString = 'date' then
ReplaceText:= DateToStr(Date)
else
if TagString = 'other' then
ReplaceText:= other; // other is a global variable
As we have seen above we can pass values to the page producer using global variables.
For example we need to extract certain information from a table and send it back
to the page producer as a tag:
In WebActionItem event:
Table1.Locate('login', Request.QueryFields.Values['login'], []);
FullName:= Table1.FieldByName('fullname').AsString;
Table1.Close;
Response.Content:= PageProducer1.Content;
and we should write some thing like this in PageProducer's OnTag event:
if TagString = 'fullname' then
ReplaceText:= FullName;
OnTag event is executed when we read Content property of PageProducer, for example
below line of code will execute OnTag event according to it's static page tags count:
Response.Content:= PageProducer1.Content;
We can put an entire HTML table in a tag because we are using Delphi's ansi string.